package com.shiguiwu.springmybatis.designpattern.composite;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.DoubleStream;

/**
 * @description: 文件夹
 * @author: stone
 * @date: Created by 2021/2/25 22:59
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.composite
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Folder extends Catalog {

    private String name;

    private Double size;

    List<Catalog> files = new ArrayList<>();

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public Double getSize() {
        return files.stream().mapToDouble(Catalog::getSize).sum();
    }

    @Override
    public void add(Catalog catalog) {
        files.add(catalog);
    }

    @Override
    public void print() {
       files.forEach(Catalog::print);
    }
}
